﻿using System;
using System.Linq;
using System.Xml.Linq;
using System.ComponentModel;
using Microsoft.Data.Entity.Design.Extensibility;
using System.Collections.Generic;
using System.Windows.Forms;

namespace CslaExtension.Designer
{
	class CslaDesignerExtension : CslaExtensionBase
	{

		public CslaDesignerExtension(XElement parent, PropertyExtensionContext context)
		{
			_context = context;
			_parent = parent;
		}


        [DisplayName("业务逻辑层名称空间")]
		[Description("业务逻辑层名称空间")]
		[Category(Constants._category)]
		public string CslaNamespace
		{
			get { return getValue(Constants._xnCslaNamespace); }
			set { setValue(Constants._xnCslaNamespace, value); }
		}

        [DisplayName("数据访问层名称空间")]
        [Description("数据访问层名称空间")]
        [Category(Constants._category)]
        public string CslaEntitiesNamespace
        {
            get { return getValue(Constants._xnCslaEntitiesNamespace); }
            set { setValue(Constants._xnCslaEntitiesNamespace, value); }
        }

        [DisplayName("是否允许null类型")]
		[Description("是否允许null类型")]
		[Category(Constants._category)]
		[DefaultValue(false)]
		public bool CslaNullableTypes
		{
			get 
			{
				bool result = false;
				bool.TryParse(getValue(Constants._xnCslaNullableTypesNamespace), out result);
				return result;
			}
			set { setValue(Constants._xnCslaNullableTypesNamespace, value.ToString()); }
		}

        [DisplayName("生成文件的选项")]
		[Description("生成文件的选项")]
		[Category(Constants._category)]
        [DefaultValue(CslaMultipleFilesOutput.AllClassesInSingleFile)]
		public CslaMultipleFilesOutput CslaMultipleFiles
		{
			get
			{
                CslaMultipleFilesOutput result = CslaMultipleFilesOutput.AllClassesInSingleFile;
                Enum.TryParse<CslaMultipleFilesOutput>(getValue(Constants._xnCslaMultipleFilesNamespace), out result);
				return result;
			}
            set { setValue(Constants._xnCslaMultipleFilesNamespace, value.ToString()); }
		}

        [DisplayName("事务选项")]
        [Description("增删改查时的事务选项")]
        [Category(Constants._category)]
        [DefaultValue(CslaTransactionalTypes.TransactionScope)]
        public CslaTransactionalTypes CslaTransactionType
        {
            get
            {
                CslaTransactionalTypes result = CslaTransactionalTypes.TransactionScope;
                Enum.TryParse<CslaTransactionalTypes>(getValue(Constants._xnCslaTransactionType), out result);
                return result;
            }
            set { setValue(Constants._xnCslaTransactionType, value.ToString()); }
        }
	}
}
